﻿@using MvcPaging
@model MvcPaging.IPagedList<DocumentTrackingSystem.Models.Office>
 
<script src="@Url.Content("~/Scripts/jquery.blockUI.js")" type="text/javascript"></script>
@{
    ViewBag.Title = "Office Management";
    Layout = "~/Areas/admin/Views/Shared/_AdminLayout.cshtml";
    
    
}

<h2>Offices</h2>
<p class="noprint">
    <a href="javascript:void(0);"  class="btn primary new">[+] Add New Office</a>
</p>
@Html.ActionLink("Sort by Short Name", "Index", new { page = 1, sortby = "shortname"}) | 
@Html.ActionLink("Sort by Name", "Index", new { page = 1, sortby = "name"}) | 
<div id="category-list">
    @Html.Partial("_Index",Model)
</div>

<div id="my-modal" class="modal hide fade">
    <div class="modal-header">
        <a href="#" class="close">&times;</a>
        <h3>Office Details</h3>
    </div>
    <div class="modal-body">
        <div id="msgError"></div>
        <p class="body">
                   
        </p>
    </div>
    <div class="modal-footer">
             
    </div>
</div>

<div class="pagingContainer noprint">
    @Html.Pager(Model.PageSize, Model.PageNumber, Model.TotalItemCount, new { sortby = ViewBag.sortby })
</div>



<script language="javascript" type="text/javascript">
    function clearErrors() {
        $('#msgErrorNewLocationDetails').html('');
        $('#msgError').html('');
    }

    function writeError(control, msg) {
        var err_msg = '<div class="alert-message error"><a class="close" href="#">×</a><p>' + msg + '</p></div>';
        $('#' + control).html(err_msg);
    }

    $(document).ready(function () {

        $('.closeModal').live('click', function () {
            $('#my-modal').modal('hide');
        });

        $('#my-modal form').live('submit', function () {
            clearErrors();
            $.post($(this).attr('action'), $(this).serialize(), function (data, status) {
                $('#my-modal').modal('hide');
                $("#category-list").html(data);
                alert("Record Saved!");
            }).error(function (error, status, a, b) {
                writeError('msgError', 'Error processing request. Please check errors and try again!');
                $('.modal-body p.body').html(error.responseText);

            });
            return false;
        });

        function getRequest(url) {
            $.ajax({
                url: url,
                context: document.body,
                success: function (data) {
                    $('.modal-body p.body').html(data);
                    $(this).addClass("done");
                    $('#my-modal').modal('show');
                    $('#Article').focus();
                    $.unblockUI();
                },

                error: function (err) {

                    writeError('msgErrorNewLocationDetails', err);
                    $.unblockUI();
                }
            });

        }

        $('a.new').live('click', function () {
            clearErrors();
            $.blockUI({
                message: 'Please Wait..',
                css: {
                    border: 'none',
                    padding: '15px',
                    backgroundColor: '#fff',
                    '-webkit-border-radius': '10px',
                    '-moz-border-radius': '10px',

                    color: '#000'

                }
            });
            var url = '@Url.Action("CreateOffice","Office")';
            getRequest(url);

            return false;



        });


        $('a.edit').live('click', function () {
            clearErrors();
            $.blockUI({
                message: 'Please Wait..',
                css: {
                    border: 'none',
                    padding: '15px',
                    backgroundColor: '#fff',
                    '-webkit-border-radius': '10px',
                    '-moz-border-radius': '10px',

                    color: '#000'

                }
            });
            var id = $(this).attr("oid");
            var url = "office-edit/" + id;
            getRequest(url);

            return false;
        });



    });
</script>
